phpstudy laravel设置伪静态apache

您所在的位置:网站首页 php nginx 伪静态 phpstudy laravel设置伪静态apache

phpstudy laravel设置伪静态apache

2023-07-25 17:47| 来源: 网络整理| 查看: 265

这里写自定义目录标题 phpstudy laravel设置伪静态apache|Nginx前置条件apache打开apache路由重写的功能设置项目`.htaccess`文件phpstudy中配置网站 nginx

phpstudy laravel设置伪静态apache|Nginx

伪静态是网页开发逃不过的话题,操作起来并不是很难,但就是每次配的时候都会出现忘记了上次是咋弄的,因此一顿查,一顿看,终于配好了。等下次再需要的时候又忘记上次怎么配置的,重复往复,这大概就是程序员的小烦恼吧,有没有同感呢?因此仔细完整的记录下来是非常有必要。 下面就来看下如何配置伪静态。

前置条件

本次的配置环境:

laravelphpstudyapache或者nginx apache 打开apache路由重写的功能

该功能是apache内部功能,再apache配置文件 httpd.conf 中 ,将下面这句话前面的#去掉表示激活重写功能

LoadModule rewrite_module modules/mod_rewrite.so 设置项目.htaccess文件

laravel项目的起始文件是 public/index.php 因此该文件所在目录下会有这么一个文件 .htaccess ,想必大家都是非常清除的,将下面的代码写入文件中

Options -MultiViews -Indexes RewriteEngine On # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] # Send Requests To Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] phpstudy中配置网站

配置好路由重写后,你可以使用127.0.0.1地址直接访问,也可以使用phpstudy中的 “网站” 功能。如下添加 在这里插入图片描述 此时直接访问项目即可完成伪静态

nginx

配置方式和上面的apache一摸一样,唯一区别在于项目中nginx对应的文件名为nginx.htaccess。向该文件中添加下面内容即可。

# Check if a file exists, or route it to index.php. try_files $uri $uri/ /exploit/index.php?$query_string; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3